package 数据结构和算法入门计划8月开始.数组1588;
// https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays/
// https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays/solution/gong-shui-san-xie-yi-ti-shuang-jie-qian-18jq3/
public class 所有奇数长度子数组的和0829 {
    class Solution {
        public int sumOddLengthSubarrays(int[] arr) {
            int sum = 0;
            int n = arr.length;
            for (int start = 0; start < n; start++) {
                for (int length = 1; start + length <= n; length += 2) {
                    int end = start + length - 1;
                    for (int i = start; i <= end; i++) {
                        sum += arr[i];
                    }
                }
            }
            return sum;
        }
    }

}
